'use strict';
app.controller('modulesEditCtrl',['$scope','$stateParams','$state','modulesEditService','utilService','toaster',function($scope,$stateParams,$state,modulesEditService,utilService,toaster){

    $scope.modulesEditService=modulesEditService;

    //查询商品信息
    $scope.id=$stateParams.id;
    $scope.findById=function(){
        modulesEditService.findById($scope).then(function(result){
            switch (result.status){
                case 200:
                    $scope.modulesEditService.modules=result.data;
                    break;
                case 646:
                    toaster.pop('waiting', "提示", result.message);
                    $state.go('app.404');
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break
            }
        })
    }
    $scope.findById();

    //添加模块
    $scope.editModules=function(){
        modulesEditService.editModules($scope).then(function(result){
            switch (result.status){
                case 200:
                    toaster.pop('success', "提示", "操作成功");
                    $state.go('app.modules');
                    break;
                case 653:
                    toaster.pop('waiting', "提示", result.message);
                    $state.go('app.404');
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break;
            }
        })
    }


    $scope.findNoPageAll=function(){
        modulesEditService.findNoPageAll($scope).then(function(result){
            switch (result.status){
                case 200:
                    $scope.columns = result.data;
                    break;
                case 661:
                    toaster.pop('waiting', "提示", result.message);
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break
            }
        });
    }

    $scope.findNoPageAll();




}])